package com.xiaolin.structure.stack.linked;

/**
 * @ClassName DemoStackTest
 * @Description 描述
 * @Detail detail
 * @Author MyPC
 * @Date 2020/12/12
 * @Version 1.0
 */
public class DemoStackTest {
    public static void main(String[] args) {
        DemoStack<Person> demoStack=new DemoStack<>();
        demoStack.add(new Person(1));
        demoStack.add(new Person(2));
        demoStack.add(new Person(3));
        System.out.println(demoStack.size());
        System.out.println(demoStack.peek().age);
        System.out.println(demoStack.getElement(2).age);
        Person pop = demoStack.pop();
        System.out.println(pop.age);
        System.out.println(demoStack.size());
        Person pop2 = demoStack.pop();
        System.out.println(pop2.age);
        System.out.println(demoStack.size());
        Person pop3 = demoStack.pop();
        System.out.println(pop3.age);
        System.out.println(demoStack.size());
    }

    /**
     * @ClassName Person
     * @Description TODO
     * @Detail detail
     * @Author MyPC
     * @Date 2020/11/6
     * @Version 1.0
     */
    static class Person{
        private int age;

        public Person(int age){
            this.age=age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        /**
         * 重写equals方法，使他们比较的是age的值
         * @param obj
         * @return
         */
        @Override
        public boolean equals(Object obj) {
            if(obj instanceof Person){
                return this.age==((Person)obj).age;
            }
            return false;
        }
    }
}
